/**
 * @author <a href="mailto:enjie.xu@yunhutech.com">xiaoming</a>
 * @since 2021/6/25
 */
public class LockDemo {

    static Object objectA = new Object();

    //同步代码块
    public static void m1(){
        new Thread(()->{

            synchronized (objectA){
                System.out.println(Thread.currentThread().getName()+"外");
                synchronized (objectA){
                    System.out.println(Thread.currentThread().getName()+"中");
                    synchronized (objectA){
                        System.out.println(Thread.currentThread().getName()+"内");
                    }
                }
            }

        },"t1").start();
    }


    //同步方法
    public static synchronized void m2(){
        System.out.println("外层");
        m3();
    }

    private static synchronized void m3() {
        System.out.println("中层");
        m4();
    }

    private static synchronized void m4() {
        System.out.println("内层");
    }

    public static void main(String[] args) {
        m1();
    }
}
